#include <stdio.h>
#include <stdlib.h>
#define N 6

int r = 0;
int map[12][12] = {0};
int drt[2][8] = {{-2, -1, 1, 2, 2, 1, -1, -2}, {1, 2, 2, 1, -1, -2, -2, -1}};
void search(int n, int m, int count)
{
    if (count == 64)
    {
        printf("%dth time\n", ++r);
        for (int k = 0; k < 12; k++)
        {
            for (int g = 0; g < 12; g++)
            {
                printf("%3d", map[k][g]);
            }
            printf("\n");
        }
    }
    for (int i = 0; i < 8; i++)
    {
        if (!map[n + drt[0][i]][m + drt[1][i]])
        {
            map[n + drt[0][i]][m + drt[1][i]] = count + 1;
            search(n + drt[0][i], m + drt[1][i], count + 1);
            // 回退
            map[n + drt[0][i]][m + drt[1][i]] = 0;
        }
    }
}

int main()
{
    /*******************code*******************/
    for (int i = 0; i < 12; i++)
    {
        for (int j = 0; j < 12; j++)
        {
            if (i < 2 || i > 9 || j < 2 || j > 9)
            {
                map[i][j] = 1;
            }
            else
                map[i][j] = 0;
        }
    }
    for (int k = 0; k < 12; k++)
    {
        for (int g = 0; g < 12; g++)
        {
            printf("%3d", map[k][g]);
        }
        printf("\n");
    }
    int s, e;
    s = 0;
    e = 0;
    map[s + 2][e + 2] = 1;
    search(s + 2, e + 2, 1);
    /******************************************/
    printf("\n\n****************************\n");
    printf("Press Enter key to continue\n");
    getchar();
    return 0;
    /******************************************/
}
